{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Python Programming Introduction"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-05-21T17:50:13.054524Z",
     "start_time": "2018-05-21T17:50:13.038897Z"
    }
   },
   "source": [
    "<img src=\"image/1.jpeg\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<b>Father of Python</b> - GUIDO VAN ROSSUM"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Where can we use Python?\n",
    "1. Desktop Applications (Calculator, Notepad, etc..)\n",
    "2. Web Applications (Youtube, Dropbox, Google, Instagram, Quora, Spotify)\n",
    "3. Scientific and Numeric Computing (Scipy, Numpy)\n",
    "4. Database Applications (Library Management Systems, Pharmaceutical)\n",
    "5. Network Applications (Network Sniffer, Network Parameter extraction, Routing Algo's like OSPF)\n",
    "6. Developing Games (Battlefield, Sims 4, PUBG)\n",
    "7. Data Science (Pandas, Matplotlib, Seaborn, etc)\n",
    "8. Machine Learning (scikit)\n",
    "9. AI (AIMA - AI: A Modern Approach)\n",
    "10. IOT (Raspberry pi, Phillips(works great with low level code in c++))\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Features of Python:\n",
    "1. Simple and easy to learn\n",
    "2. Free and open source.\n",
    "3. General Purpose and high level programming language.\n",
    "4. Platform independent.\n",
    "5. Case Sensitive.\n",
    "6. Interpreted Language.\n",
    "7. Dynamically typed.\n",
    "8. Rich Library.\n",
    "9. We can write concise code using python."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "# print(\"Hello\");\n",
    "# prit(\"World\");"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# a = 10, b = 20\n",
    "# print(a+b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# a = 10\n",
    "# b = 20\n",
    "# print(a+b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "# a, b = 10, 20\n",
    "# print(a+b)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Hello World"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello World\n"
     ]
    }
   ],
   "source": [
    "print('Hello World');"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Identifiers\n",
    "\n",
    "Identifier is a user-defined name in Python like variable name, function name and class name. \n",
    "\n",
    "Rules to define identifiers:\n",
    "1. Allowed characters => Alphabets, Digits and Underscore Symbol\n",
    "2. Identifier should never start with a digit\n",
    "3. Case Sensitive\n",
    "4. No length limit\n",
    "5. Can't use reserved words for identifier"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "# abc123 = 10\n",
    "# Abc123 = 20\n",
    "\n",
    "# print(id(abc123))\n",
    "# print(id(Abc123))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-09-08T16:49:52.522738Z",
     "start_time": "2018-09-08T16:49:52.518747Z"
    },
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']\n",
      "35\n"
     ]
    }
   ],
   "source": [
    "import keyword\n",
    "print(keyword.kwlist);\n",
    "print(len(keyword.kwlist));"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10\n",
      "2421795940944\n",
      "<class 'int'>\n"
     ]
    }
   ],
   "source": [
    "d = 10;\n",
    "\n",
    "print(d);\n",
    "\n",
    "print(id(d));\n",
    "\n",
    "print(type(d))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Data Types\n",
    "\n",
    "As we know that python is Dynamically typed programming language, than why do we need to learn about data type at all?\n",
    "\n",
    "Although python automatically understands the data type, but it is important to know about data types so that we can utilize the power of data structures in future.\n",
    "\n",
    "Basic Data Types available in python are:\n",
    "<pre>\n",
    "    <b>Numeric</b> - int, float, complex (Immutable)\n",
    "    <b>Boolean</b> - bool (True/False)\n",
    "    <b>Strings</b> (Immutable)\n",
    "    <b>List</b> (Mutable, mostly used to store homogeneous data types)\n",
    "    <b>Tuple</b> (Immutable, faster compared to List)\n",
    "    <b>Set</b> (Unordered collection of items, mutable, removes duplicates)\n",
    "    <b>Dictionary</b> (Unordered collection of Key-Value Pairs, Mutable, Keys are Unique - values may not be unique)\n",
    "</pre>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Numeric Datatypes -> int, float, complex"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "# a = 5;\n",
    "\n",
    "# b = 5.0;\n",
    "\n",
    "# c = 5 + 0j;\n",
    "\n",
    "# print(type(a))\n",
    "\n",
    "# print(type(b))\n",
    "\n",
    "# print(type(c))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "# f = 1.2E34\n",
    "\n",
    "# # f = 1.23e34 and f = 1.23e+34 are equivalent\n",
    "\n",
    "# print(f)\n",
    "\n",
    "# print(type(f))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "# c = 10+20j\n",
    "\n",
    "# print(type(c))\n",
    "\n",
    "# print(c + 5)\n",
    "\n",
    "# print(isinstance(c, complex))\n",
    "\n",
    "# print(c.real)\n",
    "\n",
    "# print(c.imag)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'bool'>\n"
     ]
    }
   ],
   "source": [
    "a = True\n",
    "\n",
    "print(type(a))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "# a = 10.6e-2\n",
    "# b = false\n",
    "\n",
    "# print(type(a))\n",
    "# print(type(b))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Comments"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'\\nthis is a\\nmultiline comment - 2\\n'"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# This is a single line comment\n",
    "\n",
    "'''\n",
    "this is a \n",
    "multiline comment - 1\n",
    "'''\n",
    "\n",
    "\"\"\"\n",
    "this is a\n",
    "multiline comment - 2\n",
    "\"\"\"\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Input & Output"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# input()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# a = input()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-09-08T16:28:25.160601Z",
     "start_time": "2018-09-08T16:28:20.966402Z"
    }
   },
   "outputs": [],
   "source": [
    "# a = input()\n",
    "\n",
    "# print(type(a))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "# WAP to get two numbers from user and add them\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-14T05:07:37.345983Z",
     "start_time": "2018-08-14T05:07:35.914146Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "123\n",
      "123\n"
     ]
    }
   ],
   "source": [
    "\"\"\"\n",
    "num = input()\n",
    "print(num)\n",
    "\"\"\"\n",
    "\n",
    "# this is a comment\n",
    "\n",
    "num = int(input())\n",
    "print('%d' % (num))\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-05-22T03:29:06.004059Z",
     "start_time": "2018-05-22T03:29:05.984740Z"
    }
   },
   "outputs": [],
   "source": [
    "\n",
    "# num = input('Please enter a number: ')\n",
    "\n",
    "# print('User has entered %d. Thankyou' % num)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-09-08T16:40:08.434187Z",
     "start_time": "2018-09-08T16:40:08.428204Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5 6 string\n",
      "5 6 string\n",
      "5 6 string\n"
     ]
    }
   ],
   "source": [
    "a = 5\n",
    "\n",
    "b = 6\n",
    "\n",
    "c = 'string'\n",
    "\n",
    "print(a, b, c)\n",
    "\n",
    "print('%d %d %s' % (a, b, c))\n",
    "\n",
    "print('{0} {1} {2}'.format(a, b, c))\n",
    "\n",
    "# c a b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-09-08T16:56:45.796698Z",
     "start_time": "2018-09-08T16:56:45.782732Z"
    }
   },
   "outputs": [],
   "source": [
    "# # This entire statement won't be displayed\n",
    "\n",
    "# print('54'*6)\n",
    "\n",
    "# print(5,6,7) # sep = ' ', end = '\\n'\n",
    "\n",
    "# print('Python', 1, 2)\n",
    "\n",
    "# print(1,2,3, sep=',')\n",
    "\n",
    "# print(1,2,3, sep=',', end='!!')\n",
    "\n",
    "# print(123)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "# print('this line won't get displayed');"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "# print(\"this line won't get displayed\");"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "# print(\"this line won\"t get displayed\");"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-09-08T17:06:12.263853Z",
     "start_time": "2018-09-08T17:06:12.258865Z"
    }
   },
   "outputs": [],
   "source": [
    "# print('this line won\\'t get displayed')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-09-08T17:07:54.574171Z",
     "start_time": "2018-09-08T17:07:54.569185Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Ram said \"hi\"\n"
     ]
    }
   ],
   "source": [
    "# print('Ram says \"hi\"')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "# print('this is\\na multi \\tline \\nstatement')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-09-08T17:08:28.727386Z",
     "start_time": "2018-09-08T17:08:28.722400Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Ram said 'this line\n",
      "won't get \n",
      "displayed' \n"
     ]
    }
   ],
   "source": [
    "print('''Ram said 'this line\n",
    "won't get \n",
    "displayed' ''')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-09-09T07:29:59.457009Z",
     "start_time": "2018-09-09T07:29:59.454018Z"
    }
   },
   "source": [
    "### Operators\n",
    "\n",
    "Operator is a symbol that perform certain operation.\n",
    "\n",
    "Operators available in python are:\n",
    "\n",
    "1. Arithmatic (+, -, *, /, %, //, ***)\n",
    "2. Relational (>, >=, <, <=)\n",
    "3. Equality (==, !=)\n",
    "4. Logical (and, or, not)\n",
    "5. Bitwise (&, |, ^, ~, <<, >>)\n",
    "6. Assignment (=, +=, -=, *=, /=, etc..)\n",
    "7. Ternary\n",
    "8. Identity --> is, is not (used for address comparision)\n",
    "9. Membership --> in, not in"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a+b =  14\n",
      "a-b =  6\n",
      "a*b =  40\n",
      "a/b =  2.5\n",
      "a%b =  2\n",
      "a//b =  2\n",
      "a**b =  10000\n"
     ]
    }
   ],
   "source": [
    "# Arithmatic Operators\n",
    "\n",
    "a = 10;\n",
    "b = 4;\n",
    "print('a+b = ', a+b);\n",
    "print('a-b = ', a-b);\n",
    "print('a*b = ', a*b);\n",
    "print('a/b = ', a/b);\n",
    "print('a%b = ', a%b);\n",
    "print('a//b = ', a//b);\n",
    "print('a**b = ', a**b);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "# # Relational Operators\n",
    "\n",
    "# a = 10;\n",
    "# b = 6;\n",
    "# print('a<b = ', a<b);\n",
    "# print('a<=b = ', a<=b);\n",
    "# print('a>b = ', a>b);\n",
    "# print('a>=b = ', a>=b);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {},
   "outputs": [],
   "source": [
    "# # Equality Operators\n",
    "\n",
    "# a = 10;\n",
    "# b = 6;\n",
    "# print('a==b ', a==b);\n",
    "# print('a!=b ', a!=b);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "# # Logical Operators\n",
    "\n",
    "# print(5 < 6 and 6 < 6)\n",
    "\n",
    "# print(5 < 6 or 6 < 6)\n",
    "\n",
    "# print(not(5 < 6 and 6 < 6))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "15\n",
      "15\n",
      "-11\n"
     ]
    }
   ],
   "source": [
    "# # Bitwise\n",
    "# # & -> if both bits are 1 then 1 otherwise 0\n",
    "# # | -> if both bits are 0 then 0 otherwise 1\n",
    "# # ^ -> if both bits are different then 1 otherwise 0\n",
    "# # ~ -> bitwise complement\n",
    "\n",
    "# print(5 & 10)\n",
    "\n",
    "# print(5 | 10)\n",
    "\n",
    "# print(5 ^ 10)\n",
    "\n",
    "# print(~10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "# # Shift Operators\n",
    "\n",
    "# print(10 << 1);\n",
    "\n",
    "# print(10 >> 1);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "metadata": {},
   "outputs": [],
   "source": [
    "# # Assignment Operators\n",
    "\n",
    "# x = 10;\n",
    "\n",
    "# x += 10;\n",
    "\n",
    "# print(x);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "# # Ternary\n",
    "\n",
    "# x = 5 if (5 < 6) else 6\n",
    "\n",
    "# y = 5 if (5 > 6) else 6\n",
    "\n",
    "# print(x, y)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Handson"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Swap two numbers\n",
    "\n",
    "# Swap two numbers without using third number\n",
    "\n",
    "# Extract ith bit of a number\n",
    "\n",
    "# Given three numbers, one of them is different. Find the different number"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  },
  "toc": {
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
